package com.deft.design.builder.builder;

import com.deft.design.builder.IComputer;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zdl
 * @description
 * @date 2022-04-19
 **/
public class CombinationMenu implements IMenu {

    private final List<IComputer> list = new ArrayList<>();
    private BigDecimal price = BigDecimal.ZERO;
    private final String grade;

    public CombinationMenu(String grade) {
        this.grade = grade;
    }

    @Override
    public IMenu appendHost(IComputer computer) {
        list.add(computer);
        price = price.add(computer.price());
        return this;
    }

    @Override
    public IMenu appendMonitor(IComputer computer) {
        list.add(computer);
        price = price.add(computer.price());
        return this;
    }

    @Override
    public IMenu appendKeyboard(IComputer computer) {
        list.add(computer);
        price = price.add(computer.price());
        return this;
    }

    @Override
    public IMenu appendMouse(IComputer computer) {
        list.add(computer);
        price = price.add(computer.price());
        return this;
    }

    @Override
    public String getDetail() {
        StringBuilder builder = new StringBuilder("\r\n---------------------------------------------------------------\r\n");
        builder.append("DIY电脑组件清单 \r\n");
        builder.append("电脑类型：").append(grade).append("\r\n");
        builder.append("电脑价格：").append(price).append("\r\n");
        for (IComputer computer : list) {
            builder.append(computer.component()).append("：").append(computer.brand()).append("  价格：").append(computer.price()).append("元 \r\n");
            builder.append("     ").append(computer.desc()).append("\r\n");
        }
        return builder.toString();
    }
}
